package restaurant;

import java.util.ArrayList;

/**
 * Represents all orders placed by the customers. The {@code CustomerOrders}
 * class is a collection of {@code Order} objects. In order to access an
 * {@code Order}, the program must go through the {@code CustomerOrders} class.
 * 
 * @author Odessa
 */

public class CustomerOrders
{

	/** The list of orders. */
	private ArrayList<Order> customerOrders;

	/** The order number. */
	private int orderNumber = 1;



	/**
	 * Instantiates the customer orders.
	 */
	public CustomerOrders() {
		customerOrders = new ArrayList<Order>();
	}



	/**
	 * Creates a new order. The {@code orderNumber} is used so that each order
	 * created has a unique order number. After the order is created, it is
	 * added to the customerOrders and the {@code orderNumber} gets incremented.
	 * 
	 * @param itemNo the item number of the items in the order.
	 * @param price the price of the item in the order.
	 * @return the newly created order.
	 */
	public Order newOrder(int itemNo, double price)
	{
		Order order = new Order(orderNumber, itemNo, price);
		add(order);
		orderNumber++;

		return order;
	}



	/**
	 * Adds the {@code order} to the customerOrders ArrayList. Takes an order
	 * and appends it to the end of the list.
	 * 
	 * @param order the order
	 */
	public void add(Order order)
	{
		customerOrders.add(order);
	}



	/**
	 * Gets the orders placed.
	 * 
	 * @return the list of all orders placed.
	 */
	public ArrayList<Order> getOrders()
	{
		return customerOrders;
	}



	/**
	 * Finds an order. It looks at all the orders in the customerOrders and
	 * returns the order with the specified order number.
	 * 
	 * @param orderNo the order number of the order to find.
	 * @return the order matching the order number entered.
	 */
	public Order find(int orderNo)
	{
		Order order = null;

		for (Order o : customerOrders) {
			int id = o.getOrderNo();

			if (id == orderNo) {
				order = o;
				break;
			}
		}

		return order;
	}

}
